import { createStore } from 'vuex'
import persist from 'vuex-persistedstate'
export default createStore({
  state: {
    list: [
      {
        name: '书籍',
        val: '正在看书籍',
        children: [{ msg: '三国演义', showSpan: true }, { msg: '西游记',showSpan: true }, { msg: '红楼梦',showSpan: true }]
      },
      {
        name: '电影',
        val: '正在看电影',
        children: [{ msg: '太极',showSpan: true }, { msg: '阿凡达',showSpan: true }, { msg: '金刚狼',showSpan: true }]
      },
      {
        name: '游戏',
        val: '正在玩游戏',
        children: [{ msg: '英雄联盟',showSpan: true }, { msg: '王者荣耀',showSpan: true }, { msg: '和平精英',showSpan: true }]
      },
      {
        name: '综艺',
        val: '正在看综艺',
        children: [{ msg: '快乐大本营',showSpan: true }, { msg: '爸爸去哪',showSpan: true }, { msg: '非诚勿扰',showSpan: true }]
      },
      {
        name: '体育',
        val: '正在看体育',
        children: [{ msg: '足球',showSpan: true }, { msg: 'NBA',showSpan: true }, { msg: '跳水',showSpan: true }]
      }
    ],
    checkIndex: 0, // 选中的索引
  },
  mutations: {
    cutTab(state,i){ // tab 切换的函数
      state.checkIndex = i;
    },
    addMsg(state,val){ // 添加内容
      let bool = state.list[state.checkIndex].children.some(item => item.msg == val);
      if (bool){
        alert('内容已存在');
        return
      }
      state.list[state.checkIndex].children.push({msg:val,showSpan: true});
    },
    msgDel(state,i){
      state.list[state.checkIndex].children.splice(i,1);
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new persist({
      storage: window.localStorage,
    }),
  ]
})
